package planesimulator.plane.wing;

import planesimulator.plane.wing.coefficients.LiftCoefficient;
import planesimulator.plane.wing.coefficients.DragCoefficient;
import com.jme.math.Vector3f;
import planesimulator.plane.CessnaCitation;
import planesimulator.plane.PlaneMath;

/**
 * Class that calculates force and torque grenerated by some vertical wing.
 * @author Jakub Klimek
 */
public class VerticalWing extends Wing {

  /**
   * 
   * @param n Name
   * @param size Area of the wing.
   * @param p Object representing aircraft.
   * @param lc Wing lift coefficient.
   * @param dc Wing dragcoefficient.
   * @param position Vector from position of wing to plane's COG.
   */
  public VerticalWing(
      String n, 
      float size, CessnaCitation p,
      LiftCoefficient lc, 
      DragCoefficient dc, 
      Vector3f position) {
    super(n, size, p, lc, dc, position);
  }

  public void calculateForceOnWing(Vector3f force) {
    float lift =
        size * wing_plane.density * lift_coeff.lift(angle_of_attack);
    float drag = size * wing_plane.density * drag_coeff.drag(angle_of_attack);
    force.x -= drag;
    force.z += lift;
  }

  public void calculateForcesOnWing(Vector3f force, Vector3f torque) {
    float lift =
        size * wing_plane.density * lift_coeff.lift(angle_of_attack);
    float drag = size * wing_plane.density * drag_coeff.drag(angle_of_attack);
    force.x -= drag;
    force.z += lift;
    Vector3f v = new Vector3f(-drag, 0.0f, lift);
    PlaneMath.vectoutprod(position, v, v);
    //System.out.println (" VERTICAL WING: " +name+" aoa "+angle_of_attack+" l/d "+lift+" "+drag+" tq: " + v.x+" "+v.y+" "+v.z);
    torque.addLocal(v);
  }
}
